package com.ruoyi.bigScreen;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.core.domain.zzw.TSafenessIndex;
import com.ruoyi.system.service.ITIndicatorsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ITSafenessIndexService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平安指数Controller
 * 
 * @author ruoyi
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/screen/safeness")
@Api(tags ="平安指数Controller")
public class ScreenSafenessIndexController extends BaseController
{
    @Resource
    private ITSafenessIndexService tSafenessIndexService;

    @Resource
    private ITIndicatorsInfoService tIndicatorsInfoService;
    /**
     * 查询平安指数列表
     */
    @GetMapping("/list")
    @ApiOperation("查询平安指数列表")
    public TableDataInfo list(TSafenessIndex tSafenessIndex)
    {
        startPage();
        List<TSafenessIndex> list = tSafenessIndexService.selectTSafenessIndexList(tSafenessIndex);
        return getDataTable(list);
    }

    /**
     * 导出平安指数列表
     */
    @Log(title = "平安指数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSafenessIndex tSafenessIndex)
    {
        List<TSafenessIndex> list = tSafenessIndexService.selectTSafenessIndexList(tSafenessIndex);
        ExcelUtil<TSafenessIndex> util = new ExcelUtil<TSafenessIndex>(TSafenessIndex.class);
        util.exportExcel(response, list, "平安指数数据");
    }

    /**
     * 获取平安指数详细信息
     */
    @GetMapping(value = "/{cSafenessId}")
    @ApiOperation("获取平安指数详细信息")
    public AjaxResult getInfo(@PathVariable("cSafenessId") Long cSafenessId)
    {
        return success(tSafenessIndexService.selectTSafenessIndexByCSafenessId(cSafenessId));
    }

    /**
     * 新增平安指数
     */
    @Log(title = "平安指数", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增平安指数")
    public AjaxResult add(@RequestBody TSafenessIndex tSafenessIndex)
    {
        return toAjax(tSafenessIndexService.insertTSafenessIndex(tSafenessIndex));
    }

    /**
     * 修改平安指数
     */
    @Log(title = "平安指数", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改平安指数")
    public AjaxResult edit(@RequestBody TSafenessIndex tSafenessIndex)
    {
        return toAjax(tSafenessIndexService.updateTSafenessIndex(tSafenessIndex));
    }

    /**
     * 删除平安指数
     */
    @Log(title = "平安指数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cSafenessIds}")
    @ApiOperation("删除平安指数")
    public AjaxResult remove(@PathVariable Long[] cSafenessIds)
    {
        return toAjax(tSafenessIndexService.deleteTSafenessIndexByCSafenessIds(cSafenessIds));
    }

    @PostMapping("/byRegionTop")
    @ApiOperation("通过地区获取平安指数top10")
    public AjaxResult ByRegionTop(TSafenessIndex tSafenessIndex){
        return AjaxResult.success(tSafenessIndexService.ByRegionTop(tSafenessIndex));
    }

    @PostMapping("/bycRegionId")
    @ApiOperation("条件查询(可根据年,月,地区id)一级平安指数")
    public AjaxResult BycRegionId(@RequestBody TSafenessIndex tSafenessIndex){
        return AjaxResult.success(tSafenessIndexService.BycRegionId(tSafenessIndex));
    }

    @PostMapping("/BycPid")
    @ApiOperation("通过一级指标id获取二级平安指数")
    public AjaxResult BycPid(TSafenessIndex tSafenessIndex){
        return AjaxResult.success(tSafenessIndexService.BycPid(tSafenessIndex));
    }

    @PostMapping("/ById")
    @ApiOperation("通过平安指数id获取右侧指标")
    public AjaxResult ById(TSafenessIndex tSafenessIndex){
        return AjaxResult.success(tSafenessIndexService.ById(tSafenessIndex));
    }

    @GetMapping("/leftBycRegId/{id}")
    @ApiOperation("通过地区id获取左侧指标和右侧的top4")
    public AjaxResult safBycRegId(@PathVariable("id") Long id){
        return success(tSafenessIndexService.safBycRegId(id));
    }
//    @GetMapping("/rightRegIdTop4/{id}")
//    @ApiOperation("通过地区id获取左侧指标前四的")
//    public AjaxResult rightRegIdTop4(@PathVariable("id") Long id){
//        return success(tSafenessIndexService.rightRegIdTop4(id));
//    }

    @GetMapping("/statistics/{safenessId}")
    @ApiOperation("平安指数二级指标右下角数据模型")
    public AjaxResult statistics(@PathVariable("safenessId") Long safenessId) throws JsonProcessingException {
        return success(tSafenessIndexService.statistics(safenessId));
    }

    @GetMapping("/describe/{cindicatorsId}")
    @ApiOperation("根据cindicatorsId获取二级指标的描述信息")
    public AjaxResult describe(@PathVariable("cindicatorsId") Long cindicatorsId){
        return success(tIndicatorsInfoService.getByIndicatorsId(cindicatorsId));
    }

}
